<?php session_start();
if ($_SESSION['MM_Username']){
require("../templates/comun.php"); 

$conexion=Obtener_Conexion(); ?>
<?php
header('content-type: text/html; charset: UTF-8');
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {

	$fecha = date("Y-m-d H:i:s");

  $updateSQL = sprintf("UPDATE swpr_codigossugeridos SET cs_status=%s, cs_comentarioestatus=%s WHERE codigo_art=%s",
					        GetSQLValueString($_POST['status'], "int"),
                       GetSQLValueString($_POST['comentariomorsa'], "text"),
                       GetSQLValueString($_POST['IdSucursal'], "text")
                       );

 // mysql_select_db($database_cnx_pizzeta, $cnx_pizzeta);
  //$result=mysql_query("SET NAMES 'UTF8'",$cnx_pizzeta) or die(mysql_error());
  $Result1 = pg_query($conexion,$updateSQL) or die("Error linea 46 - $updateSQL ");
  $creado = pg_affected_rows();
 //echo $creado."|".$updateSQL;
 header('Location: list_codigossugeridos.php');

}else{



$colname_rs_act_sucursales = "-1";
if (isset($_GET['codigo_art'])) {
  $colname_rs_act_sucursales = (get_magic_quotes_gpc()) ? $_GET['codigo_art'] : addslashes($_GET['codigo_art']);
}
//mysql_select_db($database_cnx_pizzeta, $cnx_pizzeta);
//$result=mysql_query("SET NAMES 'UTF8'",$cnx_pizzeta) or die(mysql_error());
$query_rs_act_sucursales = sprintf("SELECT * FROM swpr_codigossugeridos WHERE codigo_art = '%s' ", $colname_rs_act_sucursales);
$rs_act_sucursales = pg_query($conexion,$query_rs_act_sucursales) or die("Error linea 67 - $query_rs_act_sucursales");
$row_rs_act_sucursales = pg_fetch_assoc($rs_act_sucursales);
$totalRows_rs_act_sucursales = pg_num_rows($rs_act_sucursales);


?>
<form action="act_codigossugeridos.php" method="post" enctype="application/x-www-form-urlencoded">
<table border="0" id="pag_170" cellspacing="0" cellpadding="0" style="width:100%;height:100%;" summary="Estructura">
<tr>
	<td style="vertical-align:top;">
		<div style="background-color:#84AEC9;padding:1px 1px 1px 1px;">
			<span class="EBDSTYLE_722">Actualizar&nbsp;Codigos Sugeridos</span>
		</div>
	</td>
</tr>
<tr>
	<td style="vertical-align:top;height:100%;background-color:#D9D9D9;border-top-color:#E6E6E6;border-top-style:solid;border-top-width:1px;border-left-color:#E6E6E6;border-left-style:solid;border-left-width:1px;border-bottom-color:#808080;border-bottom-style:solid;border-bottom-width:1px;border-right-color:#808080;border-right-style:solid;border-right-width:1px;">
	  <table align="center">
	  <td style="vertical-align:top;height:100%;">
	  <table align="center">
		<tr valign="top">
		  <td nowrap align="right" class="formularioeditable">Codigo:</td>
		  <td><input type="text" name="codigo_art" id="codigo_art" value="<?php echo $row_rs_act_sucursales['codigo_art']; ?>" disabled="disabled"  size="32" class="formularioeditable"></td>
		</tr>
		<tr valign="top">
		  <td nowrap align="right" class="formularioeditable">Aplicacion:</td>
		  <td>
		  <textarea id="aplicacion" name="aplicacion" cols="50" rows="2" class="formularioeditable" disabled="disabled" ><?php echo $row_rs_act_sucursales['cs_aplicacion']; ?></textarea>
		  </td>
		<tr>
		<tr valign="top">
		  <td nowrap align="right" class="formularioeditable">Marca:</td>
		  <td><input type="text" name="marca" id="marca" disabled="disabled" value="<?php echo $row_rs_act_sucursales['cs_marca']; ?> " size="32" class="formularioeditable">
		  </td>
		<tr>
		<tr valign="top">
		  <td nowrap align="right" class="formularioeditable">Periodo de compra :</td>
		  <td><input name="periodo" id="periodo" disabled="disabled" value="<?php switch ($row_rs_act_sucursales['cs_periodo']){
              case 1:
			    	   echo "Semanal";
			         break;		   
			      case 2:
			    	   echo "Mensual";
			         break;		 
			      case 3:
			    	   echo "Semestral";
			         break;		   
			      case 4:
			    	  echo "Anual";
			        break;		        
		      //echo $row_rs_act_sucursales['cs_periodo'];
		  }
		  
		   ?>"  class="formularioeditable">
			
		  </td>
		<tr>
		<tr valign="top">
		  <td nowrap align="right" class="formularioeditable">Volumen de compra:</td>
		  <td><input type="text" name="volumen" disabled="disabled" id="volumen" value="<?php echo $row_rs_act_sucursales['cs_volumencompra']; ?>" size="10" class="formularioeditable"></td>
		</tr>
		<tr valign="top">
		  <td nowrap align="right" class="formularioeditable">Observacion:</td>
		  <td> <textarea id="observacion" name="observacion" disabled="disabled"  cols="50" rows="3" class="formularioeditable"><?php echo $row_rs_act_sucursales['cs_observacion']; ?></textarea></td>
		</tr>
		<tr valign="top">
		  <td nowrap align="right" class="formularioeditable">Cliente:</td>
		  <td>  <input id="cliente" name="cliente" disabled="disabled"  value="<?php echo $row_rs_act_sucursales['cs_numcte']; ?>" class="formularioeditable"></td>
		</tr>
		<tr valign="top">
		  <td nowrap align="right" class="formularioeditable">Socio:</td>
		  <td> <input id="socio" name="socio" disabled="disabled"  value="<?php echo $row_rs_act_sucursales['cs_numsocio']; ?>" class="formularioeditable"></td>
		</tr>
		<tr valign="top">
		  <td nowrap align="right" class="formularioeditable">Nombre Cliente:</td>
		  <td> <input id="nombrecte" name="nombrecte" disabled="disabled"  value="<?php echo $row_rs_act_sucursales['cs_numcte']; ?>" class="formularioeditable"></td>
		</tr>
		<tr valign="top">
		  <td nowrap align="right" class="formularioeditable">Nombre de quien sugiere:</td>
		  <td><input type="text" name="nombreqs" id="nombreqs" disabled="disabled"  value="<?php echo $row_rs_act_sucursales['cs_nombre']; ?>" size="32" class="formularioeditable"></td>
		</tr>
		<tr valign="top">
		  <td nowrap align="right" class="formularioeditable">Email:</td>
		  <td><input type="text" name="email" id="email" value="<?php echo $row_rs_act_sucursales['cs_email']; ?>" disabled="disabled" size="32" class="formularioeditable"></td>
		</tr>
		<tr valign="baseline">
		  <td nowrap align="right" class="formularioeditable">Comentarios Morsa:</td>
		  <td class="formularioeditable"><textarea id="comentariomorsa" name="comentariomorsa"   cols="50" rows="3" class="formularioeditable"><?php echo $row_rs_act_sucursales['cs_comentarioestatus']; ?></textarea></td>
		</tr>
		<tr valign="baseline">
		  <td nowrap align="right" class="formularioeditable">Status: </td>
		  <td><select id="status" name="status" class="formularioeditable">
			
			<option value="0" <?php if (0== $row_rs_act_sucursales['cs_status']) {echo "SELECTED";} ?> >Seleccione opcion...</option>
			<option value="1" <?php if (1==$row_rs_act_sucursales['cs_status']) {echo "SELECTED";} ?>   >Se va a comprar</option>
			<option value="2" <?php if (2== $row_rs_act_sucursales['cs_status']) {echo "SELECTED";} ?>   >No se manejara</option>
			
		  </select>
		  </td>
		</tr>
		
		
		
		<tr valign="baseline">
			<td nowrap align="right">
			   <a href="list_codigossugeridos.php" ><input type="button" value="Regresar" class="formularioeditable"></a>
				<!-- <input type="button" value="Regresar" onclick="Go('list_sucursales.php'); return false;" class="formularioeditable"> -->
			</td>
			<td>
				<input type="submit" value="Grabar" onclick="GuardarFormularioSucursales(); return false;" class="formularioeditable">
			</td>

		  
		</tr>
	  </table>
	  <input type="hidden" name="MM_update" value="form1">
	  <input type="hidden" id="IdSucursal" name="IdSucursal" value="<?php echo $row_rs_act_sucursales['codigo_art'];?>">
</td>

		  
		</tr>
	  </table>
	  </form>
<p>&nbsp;</p>

<?php
$creado = pg_affected_rows($res);
	Desconectar($conexion);
}
}else{header("Location: index.php" ); }
?>
